package com.jwthhealth_pub.old.report.view.adapter;

import android.content.Intent;
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.report.model.resbody.HraDataRes;
import com.jwthhealth_pub.old.report.view.NewReportInfoActivity;
import com.jwthhealth_pub.old.report.view.ReportEnvironmentActivity;
import com.jwthhealth_pub.old.report.view.ReportPhysicalActivity;

public class ReportHomeAdapter extends RecyclerView.Adapter {
    private int type;
    private final NewReportInfoActivity mActivity;
    private HraDataRes.DataBean mData;

    public ReportHomeAdapter(NewReportInfoActivity activity, int _type) {
        mActivity = activity;
        this.type = _type;
        this.mData = mActivity.getmPresenter().getmData();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InnerViewHolder(View.inflate(mActivity, R.layout.report_item_img_text, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final InnerViewHolder vh = (InnerViewHolder) holder;
        Resources resources = mActivity.getResources();
        if (getItemCount() == 9) {
//            if (mData.getZj() == null || mData.getZj().getSon() == null) return;
//            mData.getZj().getSon();
            switch (position+1) {
//                case 0:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_one));
//                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_one);
//                    break;
                case 1:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_one));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_one);
                    break;
                case 2:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_two));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_nin);
                    break;
                case 3:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_thi));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_two);
                    break;
                case 4:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_for));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_eig);
                    break;
                case 5:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_fiv));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_thi);
                    break;
                case 6:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_six));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_for);
                    break;
                case 7:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_sev));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_fiv);
                    break;
                case 8:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_eig));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_six);
                    break;
                case 9:
//                    vh.tv.setText(resources.getString(R.string.report_title_physical_nin));
                    vh.tv.setText(mData.getZj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_one_sev);
                    break;
                default:break;
            }
        } else {
            switch (position) {
                case 0:
//                    vh.tv.setText(resources.getString(R.string.report_title_environment_one));
                    vh.tv.setText(mData.getNhj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_one);
                    break;
                case 1:
//                    vh.tv.setText(resources.getString(R.string.report_title_environment_two));
                    vh.tv.setText(mData.getNhj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_two);
                    break;
                case 2:
//                    vh.tv.setText(resources.getString(R.string.report_title_environment_thi));
                    vh.tv.setText(mData.getNhj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_thi);
                    break;
                case 3:
                    vh.tv.setText(resources.getString(R.string.report_title_environment_for));
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_for);
                    break;
                case 4:
//                    vh.tv.setText(resources.getString(R.string.report_title_environment_fiv));
                    vh.tv.setText(mData.getNhj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_fiv);
                    break;
                case 5:
//                    vh.tv.setText(resources.getString(R.string.report_title_environment_six));
                    vh.tv.setText(mData.getNhj().getSon().get(position).getHra_type());
                    vh.iv.setBackgroundResource(R.mipmap.report_icon_two_six);
                    break;
                default:break;
            }
        }

        vh.clickLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                HraDataRes.DataBean _data = mActivity.getmPresenter().getmData();

                Intent intent;
                if (type == 1) {
                    intent = new Intent(mActivity, ReportEnvironmentActivity.class);
                    intent.putExtra("index", vh.getAdapterPosition());
                    HraDataRes.DataBean.NhjBean.SonBeanXXX sonBeanXXX = _data.getNhj().getSon().get(vh.getAdapterPosition());
                    intent.putExtra("data", sonBeanXXX);
                } else {
                    HraDataRes.DataBean.ZjBean zj = _data.getZj();
                    HraDataRes.DataBean.ZjBean.SonBeanX sonBeanX = zj.getSon().get(vh.getAdapterPosition());
                    intent = new Intent(mActivity, ReportPhysicalActivity.class);
//                    intent = new Intent(mActivity, New_ReportPhysicalActivity.class);
                    intent.putExtra("data", sonBeanX);
                }

                mActivity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (type == 0) {
            return 9;
        } else {
            return 6;
        }
    }

    private class InnerViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;
        private LinearLayout clickLayout;

        InnerViewHolder(View itemView) {
            super(itemView);

            iv = itemView.findViewById(R.id.img);
            tv = itemView.findViewById(R.id.text);
            clickLayout = itemView.findViewById(R.id.click_layout);
        }
    }

}
